home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)dynamics.c V1.18 3/13/95";
- #endif
- /*
- | file name -- dynamics.c
- |===================================================================
- |
- | V.I. Corporation
- | Copyright (c) 1990
- |
- | This program demonstrates the use of DVtools dynamics. It creates
- | a simple dial, rotating inside a circle. The rotation and
- | foreground color of the dial are controlled by one dynamic control
- | object. The rotation varies from 170 to -170 degrees, rotating
- | around the center of the circle. When the dial is in the first
- | third of the rotation, it is green; in the second third, it is
- | yellow; in the last third, it is red. The output value of an angle
- | is displayed using the text object controlled by another dynamic
- | control object.
- |
- | There is no use of the data source facility. Two VDPs are created,
- | using our own internal variables. These variables are manipulated
- | directly.
- |
- | The source of data for a dial is generated by combining the results of a
- | sine and cosine curve. This causes the dial to rotate back
- | and forth, in a varying flowing pattern. The source of data for a text
- | object is generated by mapping the input value for a dial to an output
- | rotation value, based on the ranges for VDPs.
- |
- | The program will exit automatically after the loop has completed.
- |
- |===================================================================
- */
- #include<windows.h>
-
- #include <math.h>
- #include "std.h"
- #include "dvstd.h"
- #include "dvtools.h"
- #include "VOstd.h"
- #include "Tfundecl.h"
- #include "VOfundecl.h"
- #include "VPfundecl.h"
-
-
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
-
- OBJECT screen;
- VIEW view;
- DRAWPORT drawport;
- OBJECT drawing, dial, border, text_object, anchor_point;
- OBJECT dyn_control_dial, dyn_control_text;
- OBJECT rotation_vd, color_vd, color_tt, text_vd;
- OBJECT center_point, dial_point, border_point;
- float dial_input = 0.0, text_input = 0.0, low_range_out, high_range_out;
- double low_range_in, high_range_in;
- VARDESC dial_rotation_vdp, dial_color_vdp, text_input_vdp;
- ATTRIBUTES text_attr;
- int n;
-
- /* Initialize DV-Tools - use config var DVPATH */
- make_argv(&argc,&argv,GetCommandLine());
- TInit ((char *) NULL, (char *) NULL);
-
- /* Open the requested graphics device */
- if (argc > 1)
- screen = TscOpenSet (argv[1], (char *) NULL,
- V_X_EXPOSURE_BLOCK, YES, V_END_OF_LIST);
-
- /* Open the default graphics device defined in DataViews
- Configuration file */
- else
- screen = TscOpenSet ((char *) NULL, (char *) NULL,
- V_X_EXPOSURE_BLOCK, YES, V_END_OF_LIST);
-
- /* Unable to open device - notify user and exit */
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- exit (EXIT_ERR);
- }
-
- /* Create a new, empty view */
- view = TviCreate ();
-
- /* Create a drawport using the view */
- drawport = TdpCreate (screen, view, (RECTANGLE *)NULL, (RECTANGLE *)NULL);
-
- /* Get the empty drawing from the view */
- drawing = TviGetDrawing (view);
-
- /* Create point objects to define graphical objects */
- center_point = VOptCreate (WORLD_COORDINATES, 0, 0, (OBJECT) NULL);
- dial_point = VOptCreate (WORLD_COORDINATES, 0, 4000, (OBJECT) NULL);
- border_point = VOptCreate (WORLD_COORDINATES, 0, 4200, (OBJECT) NULL);
-
- /* Create a line dial and a circle border */
- dial = VOlnCreate (center_point, dial_point, (ATTRIBUTES *) NULL);
- border = VOciCreate (center_point, border_point, (ATTRIBUTES *) NULL);
-
- /* Create a text object to display output value of a dynamic action. */
- anchor_point = VOptCreate (WORLD_COORDINATES, 0, -8000, (OBJECT) NULL);
- VOuAtInit (&text_attr);
- text_attr.foreground_color = VOcoCreate (COLOR_COMPONENTS, 255, 0, 0); /*red*/
- text_object = VOtxCreate (" ", anchor_point, &text_attr);
-
- /* add created objects to a drawing */
- VOdrObAdd (drawing, dial);
- VOdrObAdd (drawing, border);
- VOdrObAdd (drawing, text_object);
-
- /* Create vdp's to control the dial input, set the ranges */
- low_range_in = -2.0;
- high_range_in = 2.0;
- dial_rotation_vdp = VPvdcreate ((ADDRESS) & dial_input, V_F_TYPE);
- VPvd_drange (dial_rotation_vdp, low_range_in, high_range_in);
- dial_color_vdp = VPvdcreate ((ADDRESS) & dial_input, V_F_TYPE);
- VPvd_drange (dial_color_vdp, low_range_in, high_range_in);
-
- /* Create VD objects, for rotation and color change */
- rotation_vd = VOvdCreate (dial_rotation_vdp, NUMBER, (DATUM) 0.0);
- color_vd = VOvdCreate (dial_color_vdp, NUMBER, (DATUM) 0.0);
-
- /* Create a threshold table for color change, defaulting to green */
- color_tt = VOttCreate (color_vd, OBJECT_DATUM (OT_COLOR),
- VOcoCreate (COLOR_NAME, (LONG) "green"));
-
- /* Add the thresholds to the table - values must be normalized */
- VOttAddThresh (color_tt, (int) (32767 * 0.6666667),
- VOcoCreate (COLOR_NAME, (LONG) "red"));
- VOttAddThresh (color_tt, (int) (32767 * 0.3333333),
- VOcoCreate (COLOR_NAME, (LONG) "yellow"));
-
- /* Create a dynamic control object for the dial and set the erase
- method for speed */
- dyn_control_dial = VOdyCreate ();
- VOdySetEraseMethod (dyn_control_dial, V_DYN_ERASE_BGCLR);
-
- /* Set the range of angles - the smaller "high" range enables a clockwise
- rotation as the value of dial_input increases */
- low_range_out = 170.0;
- high_range_out = -170.0;
-
- /* Attach the two data objects to the dial dynamic control object */
- VOdyAttachData (dyn_control_dial, V_DYN_ROTATE, rotation_vd, &low_range_out,
- &high_range_out, center_point, (OBJECT) NULL);
- VOdyAttachData (dyn_control_dial, FOREGROUND_COLOR, color_tt, (float *) NULL,
- (float *) NULL, (OBJECT) NULL, (OBJECT) NULL);
-
- /* Attach the dynamic control object to the dial */
- VOobDySet (dial, dyn_control_dial);
-
- /* Create a vdp to control the text_object input */
- text_input_vdp = VPvdcreate ((ADDRESS) & text_input, V_F_TYPE);
-
- /* Create a VD object for text dynamics */
- text_vd = VOvdCreate (text_input_vdp, NUMBER, (DATUM) 0.0);
-
- /* create a dynamic control object for the text object */
- dyn_control_text = VOdyCreate ();
-
- /* Attach the text data object to the text dynamic control object */
- VOdyAttachData (dyn_control_text, V_DYN_TEXT, text_vd, (float *) NULL,
- (float *) NULL, (OBJECT) NULL, (OBJECT) NULL);
-
- /* Specify the format string to be used for the text dynamics */
- VOdySetTextFormat (dyn_control_text, V_DYN_TEXT, "rotation value = %8.2f");
-
- /* Attach the dynamic control object to the text object */
- VOobDySet (text_object, dyn_control_text);
-
- /* Draw the objects */
- TdpDraw (drawport);
-
- /* Loop: change the dial input,text input and update the dynamic objects */
- for (n = 0; n < 2000; n++)
- {
- dial_input = sin ((double) (n / 15.0)) - cos ((double) (n / 25.0));
-
- /* Get a mapped output value for the angle */
- text_input = dial_input * (high_range_out - low_range_out) /
- (high_range_in - low_range_in);
-
- TdpDrawNext (drawport);
- }
-
- /* Exit gracefully */
- TdpDestroy (drawport);
- TviDestroy (view);
- TscClose (screen);
- TTerminate ();
- return EXIT_OK;
- }
-